<?php
/**
* /ezadm/logic/agent/agent.php
* 개별홈페이지관리 로직 처리
* kimsb <ksb1110@nextez.co.kr>
* 2013-02-13
**/
// 경로 / 인증 체크
include_once dirname(__FILE__) . '/../../inc.auth.php';

// 클래스 인스턴스
$App->class_require('File');
$App->class_require('Table.TmsHomepageInfo');
$App->class_require('Table.PmsHomepageMember');
$App->class_require('Table.PmsHomepageSet');
$App->class_require('Table.PmsHomepageMenu');

$File = new File();
$TmsHomepageInfo		= new TmsHomepageInfo(&$Db);
$PmsHomepageMember		= new PmsHomepageMember(&$Db);
$PmsHomepageSet			= new PmsHomepageSet(&$Db);
$PmsHomepageMenu		= new PmsHomepageMenu(&$Db);

if ($g_subjob == 'list')
{
	$App->class_require('Paging');
	$Paging = new Paging();

	// 변수 초기화
	$page		= $App->nvl('page', (($App->nvl('id1')!=''?$App->nvl('id1'):1)));
	$column		= $App->nvl('column');
	$keyword	= $App->nvl('keyword');

	$wheres = array();
	$wheres[] = '1=1';
	if ($keyword)	$wheres[] = "{$column} LIKE '%{$keyword}%'";
	$TmsHomepageInfo->paging(&$Paging, $wheres, $page, 15, 10);
	$Paging->set_total_num($TmsHomepageInfo->count($wheres[0]));

	$list = $TmsHomepageInfo->get_list('*',$wheres,  'hi_ctime DESC ');

	$hi_lang_arr = explode(",",$record['hi_lang']);
}
else if ($g_subjob == 'insert_form')
{
	//언어선택 부분
	//$TmsHomepageInfo->_lang;
}
else if ($g_subjob == 'insert')
{
	if (!$App->check_method(POST)) $Error->fail(NO_PERMIT_METHOD);

	//1. 2차도메인 체크
	if ($TmsHomepageInfo->check("UPPER(hi_domain) = '" . strtoupper($_POST['hi_domain']) . "'") || strtoupper($_POST['hi_domain']) == strtoupper($TmsHomepageInfo->_source_domain))
	{
		echo "
			<script type='text/javascript'>
			//<![CDATA[
				alert('입력한 2차도메인은 이미 사용중입니다.');
			//]]>
			</script>
		";
		exit;
	}

	//hi_lang_arr
	//2. 언어설정 체크
	if(count($_POST['hi_lang_arr']) < 1)
	{
		echo "
			<script type='text/javascript'>
			//<![CDATA[
				alert('언어를 한가지 이상 체크해주세요');
			//]]>
			</script>
		";
		exit;
	}

	$_POST['hi_lang'] = implode(",",$_POST['hi_lang_arr']);

	$_POST['hi_layout'] = "template01";
	$_POST['hi_design'] = "skin01";

	if ($TmsHomepageInfo->insert($_POST, array('hi_ctime')))
	{
		$hi_seq = $TmsHomepageInfo->insert_id();

		//1. 홈페이지 관리자 생성
		$PmsAdmin['ha_id']			= "admin";
		$PmsAdmin['ha_hiseq']		= $hi_seq;
		$PmsAdmin['ha_name']		= "관리자";
		$PmsAdmin['ha_pw']			= $_POST['hi_domain'];
		$PmsAdmin['ha_level']		= "50";
		$PmsAdmin['ha_use_flag']	= "1";
		$PmsHomepageMember->insert($PmsAdmin, array('ha_ctime'));

		//2. 홈페이지 디렉토리 생성
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'], 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/web', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/img', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/mov', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/doc', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/qrcode', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/ezbbs', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/popup', 0777, false);
		$File->new_directory($App->_dir_agency.'/data/'.$_POST['hi_domain'] . '/banner', 0777, false);
		$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'], 0777, false);
		$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/ezadm', 0777, false);

		foreach($_POST['hi_lang_arr'] as $v)
		{
			$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v), 0777, false);
			$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . '/contents', 0777, false);
			$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . '/template', 0777, false);
		}


		//3. 파일 복사
		foreach($_POST['hi_lang_arr'] as $v)
		{
			if($TmsHomepageInfo->source_copy("/index.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . "/index.php", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/index.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/index.php", 0777);

			//메뉴파일 복사
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/inc.menus.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/inc.menus.php", 0777);
			//메뉴파일 디비 인서트


			//템플릿파일 복사
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0101.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0101.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0102.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0102.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0103.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0103.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0201.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0201.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0202.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0202.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0302.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0302.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0303.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0303.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0303.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0303.htm", 0777);
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0401.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0401.htm", 0777);

			//로직파일인덱스
			if($TmsHomepageInfo->source_copy(strtolower($v) . "/contents/index.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/contents/index.php", 0777);

			//메뉴파일을 디비에 인서트 시킨다.
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "01" , "hm_lang" => $v , "hm_pname" => "행사개요" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 1,"hm_allow_sub_flag"=>1));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0101" , "hm_lang" => $v , "hm_pname" => "행사개요" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1, "hm_type" => 'C'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0102" , "hm_lang" => $v , "hm_pname" => "행사특징" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2, "hm_type" => 'C'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0103" , "hm_lang" => $v , "hm_pname" => "사무국안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 3, "hm_type" => 'C'));

			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "02" , "hm_lang" => $v , "hm_pname" => "참가안내" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 2,"hm_allow_sub_flag"=>1));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0201" , "hm_lang" => $v , "hm_pname" => "참가신청안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1, "hm_type" => 'C'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0202" , "hm_lang" => $v , "hm_pname" => "참가비/부스안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2, "hm_type" => 'C'));

			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "03" , "hm_lang" => $v , "hm_pname" => "부대행사" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 3,"hm_allow_sub_flag"=>1));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0301" , "hm_lang" => $v , "hm_pname" => "학술행사" , "hm_depth" => 2 , "hm_board" => "study" , "hm_sort" => 1, "hm_type" => 'C'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0302" , "hm_lang" => $v , "hm_pname" => "사업설명회" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2, "hm_type" => 'C'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0303" , "hm_lang" => $v , "hm_pname" => "이벤트" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 3, "hm_type" => 'C'));

			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "04" , "hm_lang" => $v , "hm_pname" => "참관안내" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 4,"hm_allow_sub_flag"=>1));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0401" , "hm_lang" => $v , "hm_pname" => "참관안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1, "hm_type" => 'C'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0402" , "hm_lang" => $v , "hm_pname" => "온라인사전등록" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2 , "hm_url" => "/receipt/receipt.php", "hm_type" => 'L'));

			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "05" , "hm_lang" => $v , "hm_pname" => "미디어센터" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 5,"hm_allow_sub_flag"=>1));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0501" , "hm_lang" => $v , "hm_pname" => "공지사항" , "hm_depth" => 2 , "hm_board" => "notice" , "hm_sort" => 1, "hm_type" => 'B'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0502" , "hm_lang" => $v , "hm_pname" => "자료실" , "hm_depth" => 2 , "hm_board" => "file" , "hm_sort" => 2, "hm_type" => 'B'));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0503" , "hm_lang" => $v , "hm_pname" => "홍보동영상" , "hm_depth" => 2 , "hm_board" => "movie" , "hm_sort" => 3, "hm_type" => 'B'));

			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "06" , "hm_lang" => $v , "hm_pname" => "사이트도우미" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 6,"hm_allow_sub_flag"=>1));
			$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0601" , "hm_lang" => $v , "hm_pname" => "사이트맵" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1 , "hm_url" => "/sitemap/sitemap.php", "hm_type" => 'L'));
		}

		if($TmsHomepageInfo->source_copy("ezadm/index.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . "/ezadm/index.php", 0777);

		//4. QR코스 생성
		$TmsHomepageInfo->create_qrcode($_POST["hi_domain"]);

		//5. 관련 게시판 생성( notice , file )
		// 자료실 게시판 그룹 - 관리자에서 쓸 게시판
		$arr_board = array('NOTICE' => '공지사항', 'FILE' => '자료실', 'MOVIE' => '홍보동영상', 'STUDY' => '학술행사');
		foreach($arr_board as $k => $v)
		{
			create_agent_board($_POST["hi_domain"], $k, $v, 5);
		}

		// 게시판 그룹 만들기
		set_board_group($_POST["hi_domain"], $_POST['hi_homepage_name']);

		echo "
			<script type='text/javascript'>
			//<![CDATA[
				alert('홈페이지가 생성되었습니다.');
				parent.opener.document.location.reload();
				parent.close();
			//]]>
			</script>
		";
	}
	else $Error->fail(INSERT_FAIL);
}
else if ($g_subjob == 'update_form')
{
	if (!$App->check_method(GET)) $Error->fail(NO_PERMIT_METHOD);

	if ($record = $TmsHomepageInfo->get_a_record('', array($_GET['id1'])))
	{
		$TmsHomepageInfo->htmlchars($record);

		$hi_lang_arr = explode(",",$record['hi_lang']);
	}
	else $Error->fail(NOT_FIND_DATA);
}
else if ($g_subjob == 'update')
{
	if (!$App->check_method(POST)) $Error->fail(NO_PERMIT_METHOD);

	//hi_lang_arr
	//2. 언어설정 체크
	if(count($_POST['hi_lang_arr']) < 1)
	{
		echo "
			<script type='text/javascript'>
			//<![CDATA[
				alert('언어를 한가지 이상 체크해주세요');
			//]]>
			</script>
		";
		exit;
	}

	$_POST['hi_lang'] = implode(",",$_POST['hi_lang_arr']);

	if ($TmsHomepageInfo->update($_POST, array($_POST['hi_seq']), array('hi_utime')))
	{
		$hi_seq = $_POST['hi_seq'];

		foreach($_POST['hi_lang_arr'] as $v)
		{
			if (!is_dir($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v)))
			{
				$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v), 0777, false);
				$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . '/contents', 0777, false);
				$File->new_directory($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . '/template', 0777, false);

				if($TmsHomepageInfo->source_copy(strtolower($v) . "/index.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/index.php", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/inc.menus.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/inc.menus.php", 0777);

				//템플릿파일 복사
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0101.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0101.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0102.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0102.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0103.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0103.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0201.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0201.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0202.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0202.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0302.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0302.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0303.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0303.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0303.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0303.htm", 0777);
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/template/0401.htm", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/template/0401.htm", 0777);

				//로직파일인덱스
				if($TmsHomepageInfo->source_copy(strtolower($v) . "/contents/index.php", $_POST["hi_domain"])) @chmod($App->_dir_site.'/'.$_POST['hi_domain'] . '/' . strtolower($v) . "/contents/index.php", 0777);

				//메뉴파일을 디비에 인서트 시킨다.
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "01" , "hm_lang" => $v , "hm_pname" => "행사개요" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 1,"hm_allow_sub_flag"=>1));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0101" , "hm_lang" => $v , "hm_pname" => "행사개요" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1, "hm_type" => 'C'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0102" , "hm_lang" => $v , "hm_pname" => "행사특징" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2, "hm_type" => 'C'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0103" , "hm_lang" => $v , "hm_pname" => "사무국안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 3, "hm_type" => 'C'));

				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "02" , "hm_lang" => $v , "hm_pname" => "참가안내" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 2,"hm_allow_sub_flag"=>1));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0201" , "hm_lang" => $v , "hm_pname" => "참가신청안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1, "hm_type" => 'C'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0202" , "hm_lang" => $v , "hm_pname" => "참가비/부스안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2, "hm_type" => 'C'));

				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "03" , "hm_lang" => $v , "hm_pname" => "부대행사" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 3,"hm_allow_sub_flag"=>1));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0301" , "hm_lang" => $v , "hm_pname" => "학술행사" , "hm_depth" => 2 , "hm_board" => "study" , "hm_sort" => 1, "hm_type" => 'C'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0302" , "hm_lang" => $v , "hm_pname" => "사업설명회" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2, "hm_type" => 'C'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0303" , "hm_lang" => $v , "hm_pname" => "이벤트" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 3, "hm_type" => 'C'));

				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "04" , "hm_lang" => $v , "hm_pname" => "참관안내" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 4,"hm_allow_sub_flag"=>1));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0401" , "hm_lang" => $v , "hm_pname" => "참관안내" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1, "hm_type" => 'C'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0402" , "hm_lang" => $v , "hm_pname" => "온라인사전등록" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 2 , "hm_url" => "/receipt/receipt.php", "hm_type" => 'L'));

				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "05" , "hm_lang" => $v , "hm_pname" => "미디어센터" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 5,"hm_allow_sub_flag"=>1));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0501" , "hm_lang" => $v , "hm_pname" => "공지사항" , "hm_depth" => 2 , "hm_board" => "notice" , "hm_sort" => 1, "hm_type" => 'B'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0502" , "hm_lang" => $v , "hm_pname" => "자료실" , "hm_depth" => 2 , "hm_board" => "file" , "hm_sort" => 2, "hm_type" => 'B'));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0503" , "hm_lang" => $v , "hm_pname" => "홍보동영상" , "hm_depth" => 2 , "hm_board" => "movie" , "hm_sort" => 3, "hm_type" => 'B'));

				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "06" , "hm_lang" => $v , "hm_pname" => "사이트도우미" , "hm_depth" => 1 , "hm_board" => "" , "hm_sort" => 6,"hm_allow_sub_flag"=>1));
				$PmsHomepageMenu->insert(array("hm_hiseq" => $hi_seq , "hm_id" => "0601" , "hm_lang" => $v , "hm_pname" => "사이트맵" , "hm_depth" => 2 , "hm_board" => "" , "hm_sort" => 1 , "hm_url" => "/sitemap/sitemap.php", "hm_type" => 'L'));
			}
		}

		// 이건 임시 수정시 QR코드 발급용이다. (2013-03-12, by hamhaja)
		//$TmsHomepageInfo->create_qrcode($_POST["hi_domain"]);

		echo "
			<script type='text/javascript'>
			//<![CDATA[
				alert('수정되었습니다.');
				parent.opener.document.location.reload();
				parent.close();
			//]]>
			</script>
		";
	}
	else
	{
		$Error->fail(UPDATE_FAIL);
	}
}
else if ($g_subjob == 'qrcode')
{
	if (!$App->check_method(GET)) $Error->fail(NO_PERMIT_METHOD);

	if ($record = $TmsHomepageInfo->get_a_record('', array($_GET['id1'])))
	{
		$TmsHomepageInfo->htmlchars($record);

		// 현재발급된 홈페이지 목록
		$hi_lang_arr = explode(",",$record['hi_lang']);

		// QR코드 정보
		$tmp_list = array();
		foreach ($TmsHomepageInfo->_lang as $k => $v)
		{
			if (!in_array($k, $hi_lang_arr)) continue;
			$tmp_list[] = array(
				"lang" => $k,
				"name" => $v,
				"url" => $TmsHomepageInfo->get_qrcode_url($record["hi_domain"], $k),
			);
		}
		$qrcode_list = array_chunk($tmp_list, 2);
	}
	else $Error->fail(NOT_FIND_DATA);
}
else if ($g_subjob == "qrcode_download")
{
	// check parameter
	settype($_GET["id1"], "integer");

	// 도메인 정보 추출
	if ($TmsHomepageInfo->check(array($_GET["id1"])))
	{
		$record = $TmsHomepageInfo->get_a_record("*", array($_GET["id1"]));
		$filepath = $TmsHomepageInfo->get_qrcode_filepath($record["hi_domain"], $_GET["id2"]);
		$filename = $record["hi_homepage_name"] . "-" . $TmsHomepageInfo->_lang[$_GET["id2"]] . ".png";

		// 파일 다운로드 실행
		$App->class_require('Download');
		$Download = new Download($filepath);
		$Download->set_name($filename);
		$Download->load();
	}
	else $Error->notice(NOT_FIND_DATA);
}
else if ($g_subjob == 'delete')
{
	$hi_seq = $_GET['id1'];

	//1. 홈페이지 정보 삭제
	$hi_domain = $TmsHomepageInfo->get_a_value("hi_domain","hi_seq='{$hi_seq}'");
	if (!empty($hi_domain))
	{
		if($TmsHomepageInfo->delete("hi_seq='{$hi_seq}'"))
		{
			//2. 홈페이지 관련 계정 삭제
			$PmsHomepageMember->delete("ha_hiseq='{$hi_seq}'");

			//3. 생성 파일 및 디렉토리 삭제
			$File->delete_directory($App->_dir_agency.'/data/'.$hi_domain, 0777, false);
			$File->delete_directory($App->_dir_site.'/'.$hi_domain, 0777, false);

			//4. 해당 홈페이지의 컨텐츠 삭제
			$App->class_require('Table.ComContents');
			$ComContents = new ComContents(&$Db);
			$ComContents->delete("ct_homepage_seq = '{$hi_seq}'");
			$PmsHomepageSet->delete("hsi_hiseq = '{$hi_seq}'");

			//5. 메뉴 삭제
			$PmsHomepageMenu->delete("hm_hiseq = '{$hi_seq}'");

			//6. 게시판 디비 삭제
			$App->class_require('Table.Ezbbsgrp');
			$App->class_require('Table.EzbbsgrpEzbbscnf');
			$App->class_require('Table.EzbbscnfArtcat');
			$App->class_require('Table.EzbbscnfAdd');
			$App->class_require('Table.Ezbbscnf');
			$App->class_require('Table.EzbbsFile');
			$App->class_require('Table.EzbbsReply');
			$App->class_require('Table.EzbbsLink');
			$App->class_require('Table.EzbbsAdd');
			$App->class_require('Table.Ezbbs');
			$Ezbbsgrp			= new Ezbbsgrp(&$Db);
			$EzbbsGrpEzbbsCnf	= new EzbbsGrpEzbbsCnf(&$Db);
			$EzbbscnfArtcat		= new EzbbscnfArtcat(&$Db);
			$EzbbscnfAdd		= new EzbbscnfAdd(&$Db);
			$Ezbbscnf			= new Ezbbscnf(&$Db);
			$EzbbsFile			= new EzbbsFile(&$Db, '');
			$EzbbsReply			= new EzbbsReply(&$Db);
			$EzbbsLink			= new EzbbsLink(&$Db);
			$EzbbsAdd			= new EzbbsAdd(&$Db);
			$Ezbbs				= new Ezbbs(&$Db);

			$bbs_group_list = $Ezbbsgrp->get_list('ebgp_id', sprintf("ebgp_id = '%s' ", strtoupper($hi_domain)));
			if($bbs_group_list)
			{
				foreach($bbs_group_list as $k => $v)
				{
					$board_list = $EzbbsGrpEzbbsCnf->get_list('ebgpcf_ebcfid', sprintf("ebgpcf_ebgpid='%s'", $v['ebgp_id']));
					if($board_list)
					{
						foreach($board_list as $k1=>$v1)
						{
							$EzbbscnfArtcat->delete(sprintf("ebcfac_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
							$EzbbscnfAdd->delete(sprintf("ebcfad_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
							$Ezbbscnf->delete(sprintf("ebcf_id='%s'", $v1['ebgpcf_ebcfid']));
							$EzbbsFile->delete(sprintf("ebfi_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
							$EzbbsReply->delete(sprintf("ebrp_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
							$EzbbsLink->delete(sprintf("ebln_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
							$EzbbsAdd->delete(sprintf("ebad_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
							$Ezbbs->delete(sprintf("eb_ebcfid='%s'", $v1['ebgpcf_ebcfid']));
						}
						$EzbbsGrpEzbbsCnf->delete(sprintf("ebgpcf_ebgpid='%s'", $v['ebgp_id']));
					}
				}
				$Ezbbsgrp->delete(sprintf("ebgp_id = '%s' ", strtoupper($hi_domain)));
			}


			//5. 통계삭제
			$App->class_require('Table.PmsCounter');
			$PmsCounter = new PmsCounter(&$Db, $hcn_seq);
			$PmsCounter->delete("hcn_seq = '{$hi_seq}'");

			echo "
				<script type='text/javascript'>
				//<![CDATA[
					alert('삭제되었습니다.');
					parent.document.location.reload();
				//]]>
				</script>
			";
		}
	}
}

/**
* 게시판 생성하기
* @param string		$domain			도메인
* @param string		$board_id		게시판 아이디
* @param string		$title			게시판명
* @param int		$file_num		첨부파일개수
* @return boolean
* @version 1.0.0
**/
function create_agent_board($domain, $board_id, $title, $file_num=1)
{
	global $App, $Db, $Error ;
	$App->class_require('Table.Ezbbscnf');
	$App->class_require('Table.EzbbsgrpEzbbscnf');
	$App->class_require('File');

	$Ezbbscnf		= new Ezbbscnf(&$Db);
	$GroupConfig	= new EzbbsgrpEzbbscnf(&$Db);
	$File			= new File();

	$board_id = sprintf("%s_%s", strtoupper($domain), strtoupper($board_id));

	if($board_id == sprintf("%s_%s", strtoupper($domain), strtoupper("movie")))
	{
		$board_cols = array (
			'ebcf_id'			=> $board_id,
			'ebcf_pname'		=> $title,
			'ebcf_logic2'		=> 'ezucc',
			'ebcf_skin2'		=> 'ezucc',
			'ebcf_css'			=> 'default.css',
			'ebcf_file_dir'		=> sprintf("%s/data/%s/ezbbs/%s", $App->_dir_agency, $domain, $board_id),
			'ebcf_file_url'		=> sprintf("/agency/data/%s/ezbbs/%s", $domain, $board_id),
			'ebcf_file_num'		=> $file_num,
		);
	}
	else if($board_id == sprintf("%s_%s", strtoupper($domain), strtoupper("study")))
	{
		$board_cols = array (
			'ebcf_id'			=> $board_id,
			'ebcf_pname'		=> $title,
			'ebcf_logic2'		=> 'study',
			'ebcf_skin2'		=> 'study',
			'ebcf_css'			=> 'default.css',
			'ebcf_file_dir'		=> sprintf("%s/data/%s/ezbbs/%s", $App->_dir_agency, $domain, $board_id),
			'ebcf_file_url'		=> sprintf("/agency/data/%s/ezbbs/%s", $domain, $board_id),
			'ebcf_file_num'		=> $file_num,
		);
	}
	else
	{
		$board_cols = array (
			'ebcf_id'			=> $board_id,
			'ebcf_pname'		=> $title,
			'ebcf_logic2'		=> 'notice',
			'ebcf_skin2'		=> 'notice',
			'ebcf_css'			=> 'default.css',
			'ebcf_file_dir'		=> sprintf("%s/data/%s/ezbbs/%s", $App->_dir_agency, $domain, $board_id),
			'ebcf_file_url'		=> sprintf("/agency/data/%s/ezbbs/%s", $domain, $board_id),
			'ebcf_file_num'		=> $file_num,
		);
	}

	if(!$Ezbbscnf->insert($board_cols, array('ebcf_cid', 'ebcf_ctime')))
	{
		$Error->fail("[게시판]".INSERT_FAIL);
		return false;
	}

	$group_cols = array(
		'ebgpcf_ebgpid' =>	strtoupper($domain),
		'ebgpcf_ebcfid' =>	$board_id,
	);

	if(!$GroupConfig->insert($group_cols))
	{
		$Error->fail("[게시판그룹_게시판]".INSERT_FAIL);
		return false;
	}

	if($File->new_directory(sprintf("%s/data/%s/ezbbs/%s", $App->_dir_agency, $domain, $board_id), 0777, false)!='') $Error->fail(DIR_CREATE_FAIL);

	return true;

}

/**
* 중개업소 사이트가 사용할 게시판 그룹 생성
* @version 1.0.0
**/
function set_board_group($domain, $homapage_name)
{
		global $App,$Db;
		$App->class_require('Table.Ezbbsgrp');
		$Ezbbsgrp = new Ezbbsgrp(&$Db);

		$cols = array(
			'ebgp_id'		=> strtoupper($domain),
			'ebgp_pname'	=> $homapage_name
		);
		if ($Ezbbsgrp->insert($cols)) return true;
		else return false;;
}
?>